var onoff = false;
function Tipanimate(){
	$('#bottom_tip').animate({'height':'40px'},200);
	$('#bottom_tip').delay(1000).animate({'height':'0px'},200,function(){$('#bottom_tip').html('');onoff=false;});
}
// 获取验证码
$('#getNum').click(function(){
	var inp = $('.phone').val();
	if(onoff){return false};
	onoff=true;
	if(inp == ''){
		$('#bottom_tip').html('请填写手机号码');
		Tipanimate();
	}else if(!(/^1(3|4|5|7|8)\d{9}$/.test(inp))){
		$('#bottom_tip').html('请填写正确手机号码');
		Tipanimate();
	}else{
		$.ajax({
			type:"POST",
			url: apiCollect.apiGetVerification,
			data:{
				username:inp
			},
			success:function(data){
				if(data.code=="000000"){
					var i = 61;
					var timer=setInterval(function(){
						i--;
						$('#getNum').html(i+'s');
						if(i==0){
							$('#getNum').html('获取短信验证码');
							clearInterval(timer);
						}
					},1000);
					onoff=false;
				}else{
					$('#bottom_tip').html(data.message);
					Tipanimate();
				}
			}
		});
	}
});
// 提交申请
// $('#sub-btn').on('click',function(){
// 	$('#bottom_log').hide()
// 	$('.resetPwd-succeed').show()
// })

$('#sub-btn').click(function(){
	var inp = $('.phone').val()
	var num = $('#num').val()
	var sev = $('.severs').val()
	var pwdAgain = $('#userwordAgain input').val()

	if(inp ==''){
		$('#bottom_tip').html('请输入手机号码');
		Tipanimate();
	}else if(!(/^1(2|3|4|5|7|8|9)\d{9}$/.test(inp))){
		$('#bottom_tip').html('请输入正确手机号码');
		Tipanimate();
	}else if(num ==''){
		$('#bottom_tip').html('请输入验证码');
		Tipanimate();
	}else if(sev == ''){
		$('#bottom_tip').html('请填写密码');
		Tipanimate();
	}else if(pwdAgain == ''){
		$('#bottom_tip').html('密码不一致');
		Tipanimate();
	}
	else if(sev != pwdAgain){
		$('#bottom_tip').html('密码不一致');
		Tipanimate();
	}else{
		$.ajax({
			type:"POST",
			url: apiCollect.apiPostPasswordFind,
			data:{
				username:inp,
				code:num,
				password:sev
			},
			success:function(data){
				if(data.code=='000000'){
					$('#bottom_log').hide()
					$('.resetPwd-succeed').show()
				} else {
					$('#bottom_tip').html(data.message);
					Tipanimate()
				}
			}
		});
	}
})